#pragma once

// #include <cmath>
#include <iostream>

namespace codewar {

class Thirteen
{
public:
	static long long thirt(long long n){
		const long long initValue = n;
		int m[6] = {1, 10, 9, 12, 3 ,4};
		long long testValue = 0;
		for( auto step = 0; n; ++step ){
			testValue += n % 10 * m[step%6];
			n /= 10;
		}
		return testValue == initValue ? testValue : thirt(testValue);
	}
};

}
